package com.gxzy.domain.entity;

import com.gxzy.config.FinalPoolCfg;
import com.gxzy.domain.base.BaseParent;
import com.gxzy.util.convert.MapAndStringConvert;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.HashMap;

/**
 * 角色信息
 */

@Entity
@Data
@ToString(callSuper = true)
@Builder
@NoArgsConstructor                                          //无参构造
@AllArgsConstructor                                         //有参构造
@EqualsAndHashCode(callSuper = true)
@Table(name = FinalPoolCfg.TB_ROLE_NAME)
@org.hibernate.annotations.Table(appliesTo = FinalPoolCfg.TB_ROLE_NAME, comment = "角色信息")
public class Role extends BaseParent implements Serializable {
    private static final long serialVersionUID = 1L;

    @NotNull(message = "发布者不能为空")
    @Column(columnDefinition = "BIGINT(20) COMMENT '发布者'", nullable = false)
    private Long publisher;                                    // 发布者

    @NotBlank(message = "名称不能为空")
    @Size(min = 2, max = 50, message = "名称长度应该在2-50之间")
    @Column(columnDefinition = "VARCHAR(50) COMMENT '名称'", nullable = false)
    private String name;                                        // 名称

    @Column(columnDefinition = "TEXT COMMENT '权限组'")
    @Convert(converter = MapAndStringConvert.class)
    private HashMap<String, Boolean> identity;                  // 权限组
}
